import { defHttp } from '/@/utils/http/axios';
import {
  TemplateGroupListGetResultModel,
  TemplateGroupModel,
  TemplateGroupPageListGetResultModel,
  TemplateGroupParams,
  TemplateGroupPageSearchParams,
  TemplateGroupListSearchParams,
  UpdateTemplateGroupParams,
  TemplateGroupIDType,
} from './model/TemplateGroupModel';

enum Api {
  // 字典管理接口
  PublicApi = '/gen/template-group',
  ListApi = `/gen/template-group/list`,
  PageApi = `/gen/template-group/page`,
  BatchApi = `/gen/template-group/batch`,
}
/**
 * @description:  获取数据源列表
 * @param params
 * @returns
 */
export const getTemplateGroupList = (params?: TemplateGroupListSearchParams) =>
  defHttp.get<TemplateGroupListGetResultModel>({ url: Api.ListApi, params });

/**
 * @description:  分页获取数据源列表
 * @param params
 * @returns
 */
export const getTemplateGroupPage = (params: TemplateGroupPageSearchParams) =>
  defHttp.get<TemplateGroupPageListGetResultModel>({ url: Api.PageApi, params });

/**
 * @description:  根据id获取数据源
 * @param id
 * @returns
 */
export const getTemplateGroup = (id: TemplateGroupIDType) =>
  defHttp.get<TemplateGroupModel>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  创建数据源
 * @param params
 * @returns
 */
export const createTemplateGroup = (params: TemplateGroupParams) =>
  defHttp.post<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  更新数据源
 * @param params
 * @returns
 */
export const updateTemplateGroup = (params: UpdateTemplateGroupParams) =>
  defHttp.put<boolean>({ url: Api.PublicApi, params });

/**
 * @description:  物理删除数据源
 * @param id
 * @returns
 */
export const deleteTemplateGroup = (id: TemplateGroupIDType) =>
  defHttp.delete<boolean>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  物理批量删除数据源
 * @param ids
 * @returns
 */
export const deleteTemplateGroupBatch = (ids: TemplateGroupIDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });

/**
 * @description:  逻辑删除数据源
 * @param ids
 * @returns
 */
export const logicDeleteTemplateGroup = (id: TemplateGroupIDType) =>
  defHttp.delete<boolean>({ url: `${Api.PublicApi}/${id}` });

/**
 * @description:  逻辑批量删除数据源
 * @param ids
 * @returns
 */
export const logicDeleteTemplateGroupBatch = (ids: TemplateGroupIDType[]) =>
  defHttp.post<boolean>({ url: Api.BatchApi, params: { ids } });
